<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>骡窝日报详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/newsContent.css">
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

</head>
<script>
    $(function () {
        var params = getParams();
        //定义方法,判断当前是否登录
        var user = JSON.parse(sessionStorage.getItem("user"));
        //日报评论人的id
        var authorId;
        if (params.newsId) {
            //获取日报并渲染
            $.get('/news/' + params.newsId, function (data) {
                $('#newsDetail').renderValues(data);
            });
            //日报评论
            $.get("/newscomment/" + params.newsId + "/list", function (data) {
                $("#comment").renderValues(data,
                    {
                        'getAddress':function(item,value) {
                            var add = $(item).data('href');
                            $(item).attr('href',add+value);
                        }
                    });
            })
            //评论数量
            $.get("/newscomment/" + params.newsId + "/newsCount",function (data) {
                $('#newsCount').html(data)
            })
            //通过当前登录用户和当前日报id收藏当前游记
            if(user){
                //查询当前用户是否收藏
                $.ajax({
                    async: false,
                    url:"/myCollections/news",
                    method:"get",
                    data:{
                        newsId:params.newsId,
                        userId: user.id
                    },
                    success: function (data) {
                        if (data.success) {
                            $("#collectBtn").css("color","red");
                        } else {
                            $("#collectBtn").css("color","rgb(33,37,41)");
                        }
                    }
                });
                //收藏
                //添加点击事件
                $("#collectBtn").click(function () {
                    $.post('/myCollections/news',{'newsId':params.newsId,'userId': user.id}, function (data) {
                        if (data.success) {
                            $("#collectBtn").css("color", "red");
                            $(document).dialog({
                                type: 'notice',
                                infoText:'收藏成功',
                                autoClose:800,
                                position:'center'
                            })
                        } else {
                            $("#collectBtn").css("color", "rgb(33,37,41)");
                            $(document).dialog({
                                type: 'notice',
                                infoText:'取消收藏',
                                autoClose:800,
                                position:'center'
                            })
                        }
                    })
                })
                $("#addComment").click(function () {
                    window.location.href="/mine/addNewsComment.html?newsId="+params.newsId;
                })
            }
        }
    })
</script>
<body>
<div class="newsDetail">
    <div id="newsDetail" >
        <a href="javascript:history.go(-1);" style="position: absolute;top: 10px;left: 22px;">
            <span><i class="fa fa-chevron-left fa-2x" style="color: white;"></i></span>
        </a>
        <img render-src="coverUrl">

        <div class="container">
            <div class="row typeRow">
                <div class="col-4">
                    <span class="type" render-html="catalog.name"></span>
                </div>
                <div class="col-2">
                </div>
                <div class="col-2">
                    <span>By</span>
                </div>
                <div class="col-4">
                    <span class="type">骡窝官方</span>
                </div>
            </div>

            <div class="detail">
                <h2 class="title" render-html="title"></h2>
                <div class="content" render-html="newsContent.content"></div>
            </div>
        </div>
    </div>
    <div id="comment">
        <div class="container hot">
            <h6>用户评论(<span id="newsCount"></span>)</h6>
        </div>
        <div render-loop="list">
            <div class="container row comment" >
                <div class="col-3 comment-head" >
                    <a data-href="userProfiles.html?id=" render-key="list.user.id" render-fun="getAddress">
                        <img class="rounded-circle"
                             render-src="list.user.headImgUrl" style="height: 40px">
                        <p class="authorName"><span render-html="list.user.nickName" style="font-size: small  "></span></p>
                    </a>
                </div>
                <div class="col-9 comment-right">
                    <div class="comment-content">
                        <span class="comment-date" render-html="list.commendTime" style="font-size: small"></span>
                            <p render-html="list.content"></p>
                    </div>
                </div>

            </div>

        </div>
        <div class="operation">
            <div class="d-flex justify-content-between">
                <div class="p-2" id="addComment"><i class="fa fa-commenting-o"></i> 添加你的评论</div>
                <div class="p-2"><i class="fa fa-star-o" id="collectBtn"></i></div>
            </div>
        </div>
    </div>
</div>

</body>

</html>